require(["common", "jQuery", "coAjax", "queryString", "href", "hash_routie"], function(jSouper, $, coAjax, QueryString, href, hash_routie) {
	var _num = 10;
	var _page = 0;

	function _load_goods_page(num, page) {
		coAjax.get(appConfig.goods.list_with_page_info_and_end_pay_cb_url, {
			bus_id: busInfo._id,
			num: num,
			page: page
		}, function(result) {
			var info = result.result;
			console.log("bus.goods", info.goods);
			App.set("goods", info.goods);
			var page_info = {
				total_num: info.total_num,
				total_page: info.total_page,
				page: info.page,
				num: info.num
			};
			page_info._number_list = [];
			page_info._number_list.length = info.total_page;
			App.set("$Cache.bus.goods.page_info", page_info);
		});
	};

	function _init_goods_data() {
		var queryString = new QueryString(location.hash);
		_num = queryString.get("num") || _num;
		_page = queryString.get("page") || _page;
		_load_goods_page(_num, _page);
	};
	//分页功能
	hash_routie.on("set_goods_call_back_buff", _init_goods_data);
	//商家到期时间设置
	App.set("$Event.bus.to_update_goods_cb_url", function(e, vm) {
		vm.set("$Private.$Cache.update_cb_url", true);
	});
	App.set("$Event.bus.cancel_update_goods_cb_url", function(e, vm) {
		vm.set("$Private.$Cache.update_cb_url", false);
	});
	App.set("$Event.bus.confirm_update_goods_cb_url", function(e, vm) {
		var cb_url = vm.get("$Private.$Cache.cb_url");
		if (cb_url) {
			coAjax.post(appConfig.bus.extend.goods_end_pay_cb_url, {
				goods_id: vm.get("_id"),
				cb_url: cb_url,
				args: vm.get("$Private.$Cache.args")
			}, function(result) {
				alert("success", "修改成功");
				vm.set(result.result);
			});
		}
		vm.set("$Private.$Cache.update_cb_url", false);
	});
});